package com.ktjy.controller;

import com.ktjy.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/13  11:04
 */
@Controller
//@RequestMapping("/")
public class UserController {
    Logger logger= LoggerFactory.getLogger(UserController.class);

    @RequestMapping("/list")
    public String list(HttpServletRequest request, Model model){
        String name=request.getParameter("name");
        String age=request.getParameter("age");
        logger.info("list方法进来了，请求参数name={},age={}",name,age);

        List<User> list=new ArrayList<>();
        list.add(new User(1,"张三",18));
        list.add(new User(2,"李四",19));
        list.add(new User(3,"王五",20));
        model.addAttribute("list",list);
        return "list";
    }

    @RequestMapping("/view")
    public String view(@RequestParam("id") Integer id){
        logger.info("view方法进来了"+id);
        return null;
    }

    @RequestMapping("/add")
    public String add(){
        return "add";
    }

    @RequestMapping("/save")
    public String save(User user){
        logger.info("save方法进来了：接受参数name={},age={}",user.getName(),user.getAge());
        return null;
    }
}
